import numpy
import xarray
from numpy import array, dtype

ALBERS_PROJ = """PROJCS["GDA94 / Australian Albers",
                        GEOGCS["GDA94",
                            DATUM["Geocentric_Datum_of_Australia_1994",
                                SPHEROID["GRS 1980",6378137,298.257222101,
                                    AUTHORITY["EPSG","7019"]],
                                TOWGS84[0,0,0,0,0,0,0],
                                AUTHORITY["EPSG","6283"]],
                            PRIMEM["Greenwich",0,
                                AUTHORITY["EPSG","8901"]],
                            UNIT["degree",0.01745329251994328,
                                AUTHORITY["EPSG","9122"]],
                            AUTHORITY["EPSG","4283"]],
                        UNIT["metre",1,
                            AUTHORITY["EPSG","9001"]],
                        PROJECTION["Albers_Conic_Equal_Area"],
                        PARAMETER["standard_parallel_1",-18],
                        PARAMETER["standard_parallel_2",-36],
                        PARAMETER["latitude_of_center",0],
                        PARAMETER["longitude_of_center",132],
                        PARAMETER["false_easting",0],
                        PARAMETER["false_northing",0],
                        AUTHORITY["EPSG","3577"],
                        AXIS["Easting",EAST],
                        AXIS["Northing",NORTH]]"""


def mock_get_descriptor(query_parameters):
    variables = query_parameters['variables']
    descriptor = {
        'ls5_nbar_albers': {
            'storage_units': {
                (636419476.0, -3900012.5, 1500012.5): {
                    'storage_shape': (2, 400, 400),
                    'storage_min': (636419476.0, -3999987.5, 1500012.5),
                    'irregular_indices': {
                        u'time': [636419476.0, 661302607.0]},
                    'storage_path': '/g/data/u46/public/datacube/data/LANDSAT_5_TM_NBAR_ALB_15_-40_1990.nc',
                    'storage_max': (661302607.0, -3900012.5, 1599987.5)
                }
            },
            'dimensions': [u'time', u'y', u'x'],
            'result_max': (
                numpy.datetime64('1990-12-16T10:10:07.000000000+1100'), -3956662.5, 1555062.5),
            'irregular_indices': {u'time': array(['1990-03-03T10:11:16.000000000+1100',
                                                  '1990-12-16T10:10:07.000000000+1100'],
                                                 dtype='datetime64[ns]')
                                  },
            'result_min': (
                numpy.datetime64('1990-03-03T10:11:16.000000000+1100'), -3962362.5, 1544587.5),
            'result_shape': (2, 229, 420)}}

    descriptor['ls5_nbar_albers']['variables'] = {
        name: {'nodata_value': -999, 'datatype_name': dtype('int16')}
        for name in variables
        }
    return descriptor


def mock_get_data(query_parameters):
    variables = query_parameters['variables']
    data = {
        'element_sizes': [numpy.timedelta64(921597444444444, 'ns'), 24.890829694323145, 24.94047619047619],
        'dimensions': [u'time', u'y', u'x'],
        'indices': {
            u'y': array([-3956662.5, -3956687.5, -3956712.5, -3956737.5, -3956762.5,
                         -3956787.5, -3956812.5, -3956837.5, -3956862.5, -3956887.5,
                         -3956912.5, -3956937.5, -3956962.5, -3956987.5, -3957012.5,
                         -3957037.5, -3957062.5, -3957087.5, -3957112.5, -3957137.5,
                         -3957162.5, -3957187.5, -3957212.5, -3957237.5, -3957262.5,
                         -3957287.5, -3957312.5, -3957337.5, -3957362.5, -3957387.5,
                         -3957412.5, -3957437.5, -3957462.5, -3957487.5, -3957512.5,
                         -3957537.5, -3957562.5, -3957587.5, -3957612.5, -3957637.5,
                         -3957662.5, -3957687.5, -3957712.5, -3957737.5, -3957762.5,
                         -3957787.5, -3957812.5, -3957837.5, -3957862.5, -3957887.5,
                         -3957912.5, -3957937.5, -3957962.5, -3957987.5, -3958012.5,
                         -3958037.5, -3958062.5, -3958087.5, -3958112.5, -3958137.5,
                         -3958162.5, -3958187.5, -3958212.5, -3958237.5, -3958262.5,
                         -3958287.5, -3958312.5, -3958337.5, -3958362.5, -3958387.5,
                         -3958412.5, -3958437.5, -3958462.5, -3958487.5, -3958512.5,
                         -3958537.5, -3958562.5, -3958587.5, -3958612.5, -3958637.5,
                         -3958662.5, -3958687.5, -3958712.5, -3958737.5, -3958762.5,
                         -3958787.5, -3958812.5, -3958837.5, -3958862.5, -3958887.5,
                         -3958912.5, -3958937.5, -3958962.5, -3958987.5, -3959012.5,
                         -3959037.5, -3959062.5, -3959087.5, -3959112.5, -3959137.5,
                         -3959162.5, -3959187.5, -3959212.5, -3959237.5, -3959262.5,
                         -3959287.5, -3959312.5, -3959337.5, -3959362.5, -3959387.5,
                         -3959412.5, -3959437.5, -3959462.5, -3959487.5, -3959512.5,
                         -3959537.5, -3959562.5, -3959587.5, -3959612.5, -3959637.5,
                         -3959662.5, -3959687.5, -3959712.5, -3959737.5, -3959762.5,
                         -3959787.5, -3959812.5, -3959837.5, -3959862.5, -3959887.5,
                         -3959912.5, -3959937.5, -3959962.5, -3959987.5, -3960012.5,
                         -3960037.5, -3960062.5, -3960087.5, -3960112.5, -3960137.5,
                         -3960162.5, -3960187.5, -3960212.5, -3960237.5, -3960262.5,
                         -3960287.5, -3960312.5, -3960337.5, -3960362.5, -3960387.5,
                         -3960412.5, -3960437.5, -3960462.5, -3960487.5, -3960512.5,
                         -3960537.5, -3960562.5, -3960587.5, -3960612.5, -3960637.5,
                         -3960662.5, -3960687.5, -3960712.5, -3960737.5, -3960762.5,
                         -3960787.5, -3960812.5, -3960837.5, -3960862.5, -3960887.5,
                         -3960912.5, -3960937.5, -3960962.5, -3960987.5, -3961012.5,
                         -3961037.5, -3961062.5, -3961087.5, -3961112.5, -3961137.5,
                         -3961162.5, -3961187.5, -3961212.5, -3961237.5, -3961262.5,
                         -3961287.5, -3961312.5, -3961337.5, -3961362.5, -3961387.5,
                         -3961412.5, -3961437.5, -3961462.5, -3961487.5, -3961512.5,
                         -3961537.5, -3961562.5, -3961587.5, -3961612.5, -3961637.5,
                         -3961662.5, -3961687.5, -3961712.5, -3961737.5, -3961762.5,
                         -3961787.5, -3961812.5, -3961837.5, -3961862.5, -3961887.5,
                         -3961912.5, -3961937.5, -3961962.5, -3961987.5, -3962012.5,
                         -3962037.5, -3962062.5, -3962087.5, -3962112.5, -3962137.5,
                         -3962162.5, -3962187.5, -3962212.5, -3962237.5, -3962262.5,
                         -3962287.5, -3962312.5, -3962337.5, -3962362.5]),
            u'x': array([1544587.5, 1544612.5, 1544637.5, 1544662.5, 1544687.5,
                         1544712.5, 1544737.5, 1544762.5, 1544787.5, 1544812.5,
                         1544837.5, 1544862.5, 1544887.5, 1544912.5, 1544937.5,
                         1544962.5, 1544987.5, 1545012.5, 1545037.5, 1545062.5,
                         1545087.5, 1545112.5, 1545137.5, 1545162.5, 1545187.5,
                         1545212.5, 1545237.5, 1545262.5, 1545287.5, 1545312.5,
                         1545337.5, 1545362.5, 1545387.5, 1545412.5, 1545437.5,
                         1545462.5, 1545487.5, 1545512.5, 1545537.5, 1545562.5,
                         1545587.5, 1545612.5, 1545637.5, 1545662.5, 1545687.5,
                         1545712.5, 1545737.5, 1545762.5, 1545787.5, 1545812.5,
                         1545837.5, 1545862.5, 1545887.5, 1545912.5, 1545937.5,
                         1545962.5, 1545987.5, 1546012.5, 1546037.5, 1546062.5,
                         1546087.5, 1546112.5, 1546137.5, 1546162.5, 1546187.5,
                         1546212.5, 1546237.5, 1546262.5, 1546287.5, 1546312.5,
                         1546337.5, 1546362.5, 1546387.5, 1546412.5, 1546437.5,
                         1546462.5, 1546487.5, 1546512.5, 1546537.5, 1546562.5,
                         1546587.5, 1546612.5, 1546637.5, 1546662.5, 1546687.5,
                         1546712.5, 1546737.5, 1546762.5, 1546787.5, 1546812.5,
                         1546837.5, 1546862.5, 1546887.5, 1546912.5, 1546937.5,
                         1546962.5, 1546987.5, 1547012.5, 1547037.5, 1547062.5,
                         1547087.5, 1547112.5, 1547137.5, 1547162.5, 1547187.5,
                         1547212.5, 1547237.5, 1547262.5, 1547287.5, 1547312.5,
                         1547337.5, 1547362.5, 1547387.5, 1547412.5, 1547437.5,
                         1547462.5, 1547487.5, 1547512.5, 1547537.5, 1547562.5,
                         1547587.5, 1547612.5, 1547637.5, 1547662.5, 1547687.5,
                         1547712.5, 1547737.5, 1547762.5, 1547787.5, 1547812.5,
                         1547837.5, 1547862.5, 1547887.5, 1547912.5, 1547937.5,
                         1547962.5, 1547987.5, 1548012.5, 1548037.5, 1548062.5,
                         1548087.5, 1548112.5, 1548137.5, 1548162.5, 1548187.5,
                         1548212.5, 1548237.5, 1548262.5, 1548287.5, 1548312.5,
                         1548337.5, 1548362.5, 1548387.5, 1548412.5, 1548437.5,
                         1548462.5, 1548487.5, 1548512.5, 1548537.5, 1548562.5,
                         1548587.5, 1548612.5, 1548637.5, 1548662.5, 1548687.5,
                         1548712.5, 1548737.5, 1548762.5, 1548787.5, 1548812.5,
                         1548837.5, 1548862.5, 1548887.5, 1548912.5, 1548937.5,
                         1548962.5, 1548987.5, 1549012.5, 1549037.5, 1549062.5,
                         1549087.5, 1549112.5, 1549137.5, 1549162.5, 1549187.5,
                         1549212.5, 1549237.5, 1549262.5, 1549287.5, 1549312.5,
                         1549337.5, 1549362.5, 1549387.5, 1549412.5, 1549437.5,
                         1549462.5, 1549487.5, 1549512.5, 1549537.5, 1549562.5,
                         1549587.5, 1549612.5, 1549637.5, 1549662.5, 1549687.5,
                         1549712.5, 1549737.5, 1549762.5, 1549787.5, 1549812.5,
                         1549837.5, 1549862.5, 1549887.5, 1549912.5, 1549937.5,
                         1549962.5, 1549987.5, 1550012.5, 1550037.5, 1550062.5,
                         1550087.5, 1550112.5, 1550137.5, 1550162.5, 1550187.5,
                         1550212.5, 1550237.5, 1550262.5, 1550287.5, 1550312.5,
                         1550337.5, 1550362.5, 1550387.5, 1550412.5, 1550437.5,
                         1550462.5, 1550487.5, 1550512.5, 1550537.5, 1550562.5,
                         1550587.5, 1550612.5, 1550637.5, 1550662.5, 1550687.5,
                         1550712.5, 1550737.5, 1550762.5, 1550787.5, 1550812.5,
                         1550837.5, 1550862.5, 1550887.5, 1550912.5, 1550937.5,
                         1550962.5, 1550987.5, 1551012.5, 1551037.5, 1551062.5,
                         1551087.5, 1551112.5, 1551137.5, 1551162.5, 1551187.5,
                         1551212.5, 1551237.5, 1551262.5, 1551287.5, 1551312.5,
                         1551337.5, 1551362.5, 1551387.5, 1551412.5, 1551437.5,
                         1551462.5, 1551487.5, 1551512.5, 1551537.5, 1551562.5,
                         1551587.5, 1551612.5, 1551637.5, 1551662.5, 1551687.5,
                         1551712.5, 1551737.5, 1551762.5, 1551787.5, 1551812.5,
                         1551837.5, 1551862.5, 1551887.5, 1551912.5, 1551937.5,
                         1551962.5, 1551987.5, 1552012.5, 1552037.5, 1552062.5,
                         1552087.5, 1552112.5, 1552137.5, 1552162.5, 1552187.5,
                         1552212.5, 1552237.5, 1552262.5, 1552287.5, 1552312.5,
                         1552337.5, 1552362.5, 1552387.5, 1552412.5, 1552437.5,
                         1552462.5, 1552487.5, 1552512.5, 1552537.5, 1552562.5,
                         1552587.5, 1552612.5, 1552637.5, 1552662.5, 1552687.5,
                         1552712.5, 1552737.5, 1552762.5, 1552787.5, 1552812.5,
                         1552837.5, 1552862.5, 1552887.5, 1552912.5, 1552937.5,
                         1552962.5, 1552987.5, 1553012.5, 1553037.5, 1553062.5,
                         1553087.5, 1553112.5, 1553137.5, 1553162.5, 1553187.5,
                         1553212.5, 1553237.5, 1553262.5, 1553287.5, 1553312.5,
                         1553337.5, 1553362.5, 1553387.5, 1553412.5, 1553437.5,
                         1553462.5, 1553487.5, 1553512.5, 1553537.5, 1553562.5,
                         1553587.5, 1553612.5, 1553637.5, 1553662.5, 1553687.5,
                         1553712.5, 1553737.5, 1553762.5, 1553787.5, 1553812.5,
                         1553837.5, 1553862.5, 1553887.5, 1553912.5, 1553937.5,
                         1553962.5, 1553987.5, 1554012.5, 1554037.5, 1554062.5,
                         1554087.5, 1554112.5, 1554137.5, 1554162.5, 1554187.5,
                         1554212.5, 1554237.5, 1554262.5, 1554287.5, 1554312.5,
                         1554337.5, 1554362.5, 1554387.5, 1554412.5, 1554437.5,
                         1554462.5, 1554487.5, 1554512.5, 1554537.5, 1554562.5,
                         1554587.5, 1554612.5, 1554637.5, 1554662.5, 1554687.5,
                         1554712.5, 1554737.5, 1554762.5, 1554787.5, 1554812.5,
                         1554837.5, 1554862.5, 1554887.5, 1554912.5, 1554937.5,
                         1554962.5, 1554987.5, 1555012.5, 1555037.5, 1555062.5]),
            u'time': array([
                '1990-03-03T10:11:16.000000000+1100',
                '1990-12-16T10:10:07.000000000+1100'], dtype='datetime64[ns]')
        },
        'coordinate_reference_systems': [
            {'reference_system_definition': u'seconds since 1970-01-01 00:00:00',
             'reference_system_unit': u'seconds since 1970-01-01 00:00:00'},
            {'reference_system_definition': ALBERS_PROJ,
             'reference_system_unit': u'metre'},
            {'reference_system_definition': ALBERS_PROJ,
             'reference_system_unit': u'metre'
             }],
        'size': (2, 229, 420)
    }

    data['arrays'] = {
        name: xarray.DataArray(numpy.ones((2, 400, 400), dtype=numpy.int32))
        for name in variables
        }
    return data
